package filehandler;

import evthandler.EventMessage;
import java.io.*;

/**
 *
 * @author Casper, Dennis, Jackie, Jakob
 * @version 1.00
 */
public class Writer extends BufferedWriter {

    /**
     * Writes a new file
     * @param file File to be written
     * @throws IOException
     */
    public Writer(File file) throws IOException {
        super(new FileWriter(file));
    }

    /**
     * Writes a new file or appends to an existing file
     * @param file File to be written
     * @param append If true appends to the end of the file
     * @throws IOException
     */
    public Writer(File file, boolean append) throws IOException {
        super(new FileWriter(file, true));
    }

    /**
     * Method to write a file
     * @param fileName Name of the file
     * @param ext Extension of the file
     */
    public void writeFile(String line) {
        try {
            super.write(line);
            super.close();
        } catch (IOException ex) {
            new EventMessage("File IO error", "There was an IO error").showException(ex);
        }
    }
}
